package fanx;

import java.util.Comparator;
import java.util.TreeSet;

public class test3 {
    public static void main(String[] args) {
        TreeSet<student> list = new TreeSet<>(new Comparator<student>() {
            @Override
            public int compare(student o1, student o2) {
                int i = o1.getAge() - o2.getAge();
                 i = i == 0 ? o1.getName().compareTo(o2.getName()) : i;
                return i;
            }
        });

        student t1 = new student("lu棣",11);
        student t2 = new student("cai紫倪",11);
        student t3 = new student("maonongf",12);

        list.add(t1);
        list.add(t2);
        list.add(t3);
        System.out.println(list);
    }
}

class student  {
    private String name;
    private int age;

    public student() {
    }

    public student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


}